import { getSystemConfigStorage, setSystemConfigStorage } from "@/utils/storages"

const common = {
  state: {
    systemConfig: getSystemConfigStorage() || null,
    sysPageHeader: null,
    device: "",  // 设备是pc或者mobile, pc为空
    collapse: false,  // 是否折叠
    viewFullScreen: false  // 最大化页面
  },
  mutations: {
    setSystemConfig(state, item) {
      state.systemConfig = item
    },
    setSysPageHeader(state, item) {
      state.sysPageHeader = item || null
    },
    toggleDevice(state, device) {
      state.device = device
    },
    setCollapse(state, val) {
      let collapse = state.collapse
      if (val == "undefined" || val == null || val == "") {
        collapse = !state.collapse
      } else {
        collapse = val
      }
      state.collapse = collapse
    },
    setViewFullScreen(state, val) {
      state.viewFullScreen = val
    }
  },
  actions: {
    setSystemConfig(context, item) {
      context.commit("setSystemConfig", item)
      setSystemConfigStorage(item)
      if (item && item.systemName) {
        document.title = item.systemName
      }
    },
    setSysPageHeader(context, item) {
      context.commit("setSysPageHeader", item)
    },
    toggleDevice({ commit }, device) {
      commit("toggleDevice", device)
    },
    setCollapse({ commit }, val) {
      commit("setCollapse", val)
    },
  }
}
export default common

